
import Configer from "../../../script/frame/apiModel/config/Configer";
import {DataRouter} from "../../../script/frame/dataSource/DataRouter";
import {AchievementData, AchievementType} from "../../../script/frame/dataSource/DataModel";
import {UIConfigKey} from "../../../script/constant/UIConfig";
import * as React from "../../../script/frame/apiModel/gui/React";
import {GuiId, GuiKeys} from "../../../script/controller/model/ControllerOpt";
import AchInfoPage from "../achievementBar/AchInfoPage";
import {IProps, SyncId, UISyncData, View} from "../../../script/frame/apiModel/gui/React";
import {Logger} from "../../../script/frame/apiModel/config/Logger";
import { LightButton } from "parasimon/gui/code/component/LightButton";
import {PlayerFactory} from "../../../script/frame/PlayerFactory";
import {ResumeBarInterface} from "../../interface/GuiInterface";
import {ResourceKey} from "../../../script/constant/ResourceConstant";

interface IProp {
}
interface IState {
    cost: number,
}
export default class ResumeBar extends ResumeBarInterface<IProp, IState> {
    constructor(props: IProps & IProp) {
        super(props);
        this.state = {
            visible: true,
            cost: 0,
        }
    }


    render = () => {
        const board = Configer.getResource(ResourceKey.resumeBarBoard);
        const enter = Configer.getResource(ResourceKey.resumeBarEnter);
        const canel = Configer.getResource(ResourceKey.resumeBarCanel);
        const backSize = { h: 0.13280, w: 0.16250 };
        const backPos = { x: 0.41875, y: 0.13280 }
        const allAch = DataRouter.getAchievementDatas();
        const maxAchNum = allAch.length;
        const fontSize = Configer.getUIConfig(UIConfigKey.fontSize) as number;

        return <View   key={GuiKeys.resumeBarContent} style={{ hidden: !this.state.visible, backgroundImage: board, paddingL: 0.01250, paddingT: 0.01660, width: backSize.w, height: backSize.h, left: backPos.x, top: backPos.y }}>
            <View   key={GuiKeys.resumeBarText} style={{ width: backSize.w, height: 0.04980 }}>
                是否立即复活？{'\n'}
                需消耗金币: {this.state.cost}
            </View>
            <View   key={GuiKeys.resumeBarButtonContent} style={{ height: 0.04150, width: backSize.w }}>
                <LightButton onMouseDown={this.clickCanel}   key={GuiKeys.resumeBarButtonCanel} style={{ backgroundImage: canel, height: 0.04150, width: 0.06250 }}></LightButton>
                <LightButton onMouseDown={this.click}   key={GuiKeys.resumeBarButtonEnter} style={{ backgroundImage: enter, height: 0.04150, width: 0.06250, marginL: 0.01250 }}></LightButton>
            </View>
        </View>
    }

    click = () => {
        const cost = this.state.cost;
        const localPlayer = PlayerFactory.getInstance().getLocalPlayer();
        const currentCoin = localPlayer.gold;
        if (currentCoin >= cost) {
            const syncData: UISyncData = { id: SyncId.resumeHero, param: { cost: this.state.cost } };
            this.setState({
                ...this.state,
                visible: false,
            })
            return syncData;
        }
        Logger.toastProduct('金币不足', localPlayer);
    }

    clickCanel = () => {
        const syncData: UISyncData = { id: SyncId.closeUI, param: { guiId: GuiId.resumeBar } };
        return syncData;
    }
    canel = () => {
        this.setState({
            ...this.state,
            visible: false,
        })
    }

    showResumeBar = (cost: number) => {
        this.setState({
            ...this.state,
            visible: true,
            cost: cost,
        })
    }

    // show = (player: player, achs: {[p: string]: number}) => {
    //     const backSize = { h: 0.35, w: 0.3 };
    //     const iconSize = { h: 0.045, w: 0.045 }
    //     const backPos = { x: 0.25, y: 0.5 }
    //     const allAch = DataRouter.getAchievementDatas();
    //     const maxAchNum = allAch.length;
    //     const fontSize = Configer.getUIConfig(ResourceKey.fontSize) as number;
    //
    //     const mainBarProps: GuiProps[] = [];
    //     for (let i = 0; i < maxAchNum; i++) {
    //         const achData = allAch[i];
    //         const type = achData.type;
    //         if (type === AchievementType.talent) {
    //         } else {
    //             continue;
    //         }
    //         let prop: GuiProps;
    //         if (achData && achData.id?.length > 0) {
    //             const achId = achData.id;
    //             let backgroundImage = Configer.getUIConfig(ResourceKey.talentDisable);
    //             let achNum = 0;
    //             if (achs) {
    //                 achNum = achs[achId];
    //             }
    //             const iconProps: GuiProps[] = [];
    //             if (achNum && achNum > 0) {
    //                 backgroundImage = achData?.Art ? achData?.Art : '';
    //                 const lvSize = { h: fontSize, w: fontSize };
    //                 const lvProp: GuiProps = {
    //                     text: `${achNum}`,
    //                     childNum: 0,
    //                     fontSize: 0.01,
    //                     childProps: [],
    //                     id: this.getName(),
    //
    //                     size: lvSize,
    //                     margin: { l: 0.020, t: 0.034 },
    //                 }
    //                 iconProps.push(lvProp);
    //             }
    //
    //             prop = {
    //                 backgroundImage,
    //                 childProps: iconProps,
    //                 childNum: 1,
    //                 id: this.getName(),
    //                 onMouseEnter: (player: player, position: { x: number, y: number }) => {
    //                     const infoMenuX = backPos.x + position.x;
    //                     const infoMenuY = backPos.y + position.y;
    //                     const data = { visible: true, x: infoMenuX, y: infoMenuY, achId };
    //                     this.onMouseEnter(player, data);
    //                 },
    //                 onMouseLeave:  (player: player, position: { x: number, y: number }) => {
    //                     const data = { visible: false };
    //                     this.onMouseLeave(player, data);
    //                 },
    //                 size: { h: iconSize.h, w: iconSize.w },
    //
    //                 colNum: 1,
    //                 margin: { l: 0.01, t: 0.01 },
    //             };
    //             mainBarProps.push(prop)
    //         }
    //     }
    //
    //     const closeIconSize = { h: 0.028, w: 0.045 };
    //     const closeIcon: string = Configer.getUIConfig(UIConfigKey.barCloseButton);
    //     const closeProp: GuiProps = {
    //         backgroundImage: closeIcon,
    //         childProps: [],
    //         childNum: 0,
    //         id: this.getName(),
    //
    //         position: { x: backSize.w - closeIconSize.w, y: 0 },
    //
    //         onClick: (player, position) => {
    //             this.close(player);
    //         },
    //
    //         size: closeIconSize,
    //     }
    //     mainBarProps.push(closeProp)
    //
    //     const talentBarBoard = Configer.getUIConfig(UIConfigKey.talentBarBoard);
    //     const prop: GuiProps = {
    //         backgroundImage: talentBarBoard,
    //         childProps: mainBarProps,
    //         childNum: maxAchNum + 1,
    //         id: this.getName(),
    //         position: backPos,
    //         size: backSize,
    //
    //         padding: { l: 0.005, t: 0.026 },
    //         colNum: 5,
    //     };
    //     this.toRender(player, prop, DzGetGameUI());
    // }
}